<?php
class ControllerCommonHeader extends Controller {
	protected function index() {		
		
		$this->data['title'] = $this->document->getTitle();

		if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			$this->data['base'] = HTTPS_SERVER;
		} else {
			$this->data['base'] = HTTP_SERVER;
		}

		$this->data['description'] = $this->document->getDescription();
		$this->data['keywords'] = $this->document->getKeywords();
		$this->data['links'] = $this->document->getLinks();
		$this->data['styles'] = $this->document->getStyles();
		$this->data['scripts'] = $this->document->getScripts();
		$this->data['lang'] = $this->language->get('code');
		$this->data['direction'] = $this->language->get('direction');

		$this->load->language('common/header');
		
		// Mapping all language variables
		$this->data = array_merge($this->data, $this->language->getData());

		if (!$this->user->isLogged() || !isset($this->request->get['token']) || !isset($this->session->data['token']) || ($this->request->get['token'] != $this->session->data['token'])) {
			$this->data['logged'] = '';
			
			unset($this->session->data['current_restaurant_id']);

			$this->data['home'] = $this->url->link('common/login', '', 'SSL');
		} else if($this->restaurant->getRestaurantId() == null
					&& $this->request->get['route'] != "common/home"
					&& $this->user->isRestaurantStaff()
					) {
			$this->data['logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName());

			// Redirect back to home page if restaurant id is null
			$this->redirect($this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'));
		} else {
			$this->data['logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName());

			$this->data['home'] = $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL');
			
			if($this->restaurant->getRestaurantId() != null) {
				$this->data['current_restaurant'] = sprintf($this->data['text_restaurant_current'], $this->restaurant->getName());
			} else {
				$this->data['current_restaurant'] = null;
			}
			
			// Restaurant Matrix
			$this->data['news_category'] = $this->url->link('news/category', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['news_article'] = $this->url->link('news/article', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_restaurant'] = $this->url->link('restaurant/restaurant', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_option'] = $this->url->link('restaurant/restaurant_option', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_menu_option'] = $this->url->link('menu/food_option', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_config'] = $this->url->link('restaurant/setting', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_staff'] = $this->url->link('restaurant/staff', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_menu'] = $this->url->link('menu/food', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_menu_category'] = $this->url->link('menu/menu', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant_booking'] = $this->url->link('restaurant/booking', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_sale_restaurant'] = $this->url->link('report/sale_restaurant', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['booking_status'] = $this->url->link('setting/booking_status', 'token=' . $this->session->data['token'], 'SSL');

			$this->data['attribute'] = $this->url->link('menu/attribute', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['attribute_group'] = $this->url->link('menu/attribute_group', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['backup'] = $this->url->link('setting/backup', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['banner'] = $this->url->link('content/banner', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['category'] = $this->url->link('catalog/category', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['country'] = $this->url->link('setting/country', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['coupon'] = $this->url->link('sale/coupon', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['currency'] = $this->url->link('setting/currency', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['customer'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['customer_group'] = $this->url->link('sale/customer_group', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['download'] = $this->url->link('catalog/download', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['error_log'] = $this->url->link('setting/error_log', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['feed'] = $this->url->link('extension/feed', 'token=' . $this->session->data['token'], 'SSL');

			$this->data['information'] = $this->url->link('content/information', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['language'] = $this->url->link('setting/language', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['layout'] = $this->url->link('setting/layout', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['logout'] = $this->url->link('common/logout', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['contact'] = $this->url->link('sale/contact', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['manufacturer'] = $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['module'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['option'] = $this->url->link('catalog/option', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['order'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['order_status'] = $this->url->link('setting/order_status', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['payment'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_sale_order'] = $this->url->link('report/sale_order', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_sale_tax'] = $this->url->link('report/sale_tax', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_sale_shipping'] = $this->url->link('report/sale_shipping', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_sale_return'] = $this->url->link('report/sale_return', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_sale_coupon'] = $this->url->link('report/sale_coupon', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_product_viewed'] = $this->url->link('report/product_viewed', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_product_purchased'] = $this->url->link('report/product_purchased', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_customer_order'] = $this->url->link('report/customer_order', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_customer_reward'] = $this->url->link('report/customer_reward', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['report_customer_credit'] = $this->url->link('report/customer_credit', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['review'] = $this->url->link('restaurant/review', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['food_review'] = $this->url->link('menu/review', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['shipping'] = $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['setting'] = $this->url->link('setting/setting', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['template'] = $this->url->link('setting/template', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['restaurant'] = HTTP_CATALOG;
			$this->data['total'] = $this->url->link('extension/total', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['user'] = $this->url->link('setting/user', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['user_group'] = $this->url->link('setting/user_permission', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['voucher'] = $this->url->link('sale/voucher', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['voucher_theme'] = $this->url->link('sale/voucher_theme', 'token=' . $this->session->data['token'], 'SSL');
			$this->data['zone'] = $this->url->link('setting/zone', 'token=' . $this->session->data['token'], 'SSL');
		}

		$this->template = 'common/header.tpl';

		$this->render();
	}
}
?>